// 引入 react 依赖
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Text, View, Image, TouchableOpacity, ImageBackground, ScrollView,InteractionManager } from 'react-native';

// 引入第三方依赖
import _ from 'lodash';
import pureRender from 'pure-render-decorator';
import { Actions } from 'react-native-router-flux';

// antd 按需加载
import { Button } from 'antd-mobile-rn';

// 引入 处理数据 所需文件
import { } from './module.js'

// 引入样式
import Styles from './style.js';

// 引入公用组件
import { } from '../../components/index.js'

// 引入工具包
import { press, size, ScreenWidth , defaultDataList,onEndReached,onRefresh ,concatDataList,defaultPage} from '../../util/utils.js'
class RnButton extends Component {

	static propTypes = {

	}

	constructor(props) {
		super(props)
		this.state = {}
	}

	render() {
		const { children, size, style, ghost, type, disabled, onPress } = this.props

		let backgroundColor = '#fff'
		let color = 'rgba(0, 0, 0, 0.65)'
		let borderColor = '#d9d9d9'
		let disabledBackgroundColor = '#f5f5f5'
		let disabledColor = 'rgba(0, 0, 0, 0.25)'
		let disabledBorderColor = '#d9d9d9'
		let width = 80
		let height = 30
		let fontSize = 14
		let borderRadius = 4

		let primary = {
			backgroundColor: '#1890ff',
			color: '#fff',
			borderColor: '#1890ff',
		}
		let dashed = {
			backgroundColor: '#fff',
			color: '#F04844',
			borderColor: '#F04844',
		}
		let danger = {
			borderColor: '#e94f4f',
			backgroundColor: '#e94f4f',
			color: '#fff',
		}
		let link = {
			borderColor: 'none',
			backgroundColor: 'none',
			color,
		}

		let large = {
			width: 80,
			height: 30,
			borderRadius: 4,
			fontSize: 14,
			lineHeight: 16,
		}

		let small = {
			width: 80,
			height: 30,
			borderRadius: 4,
			fontSize: 14,
			lineHeight: 16,
		}

		if (size && size == 'large') {
			width = large.width
			height = large.height
			borderRadius = large.borderRadius
			fontSize = large.fontSize
			lineHeight = large.lineHeight
		}

		if (size && size == 'small') {
			width = small.width
			height = small.height
			borderRadius = small.borderRadius
			fontSize = small.fontSize
			lineHeight = small.lineHeight
		}

		if (ghost) {
			borderColor = '#F04844'
			backgroundColor = ''
			color = '#F04844'

			// 一般用于确认按钮
			if (type && type == 'primary') {
				backgroundColor = 'none'
				color = primary.backgroundColor
				borderColor = primary.borderColor
			}

			// 虚线按钮
			if (type && type == 'dashed') {
				backgroundColor = 'none'
				color = dashed.backgroundColor
				borderColor = dashed.borderColor
			}

			// 危险按钮，一般用于
			if (type && type == 'danger') {
				backgroundColor = 'none'
				color = danger.backgroundColor
				borderColor = danger.borderColor
			}

			// 无边框以及背景
			if (type && type == 'link') {
				backgroundColor = 'none'
				color = link.backgroundColor
				borderColor = link.borderColor
			}
		} else {

			// 一般用于确认按钮
			if (type && type == 'primary') {
				backgroundColor = primary.backgroundColor
				color = primary.color
				borderColor = primary.borderColor
			}

			// 虚线按钮
			if (type && type == 'dashed') {
				backgroundColor = dashed.backgroundColor
				color = dashed.color
				borderColor = dashed.borderColor
			}

			// 危险按钮，一般用于
			if (type && type == 'danger') {
				backgroundColor = danger.backgroundColor
				color = danger.color
				borderColor = danger.borderColor
			}

			// 无边框以及背景
			if (type && type == 'link') {
				backgroundColor = link.backgroundColor
				color = link.color
				borderColor = link.borderColor
			}

		}

		if (disabled) {
			borderColor = disabledBorderColor
			backgroundColor = disabledBackgroundColor
			borderColor = disabledBorderColor
			color = disabledColor
		}

		let TouchStyle = {
			width,
			height,
			borderRadius,
			borderWidth: 0.5,
			borderColor,
			backgroundColor,
			flexDirection: 'row',
			alignItems: 'center',
			justifyContent: 'center',
			...style
		}

		let TestStyle = {
			fontSize,
			color,
			lineHeight: height,
		}

		return (
			<TouchableOpacity
				onPress={() => {
					if (onPress && !disabled) {
						onPress()
					}
				}}
				style={TouchStyle}
			>
				<Text style={TestStyle}>{children}</Text>
			</TouchableOpacity>
		)
	}
}

export default pureRender(RnButton)
